import Vue from 'vue'
import Router from 'vue-router'
import Index from '../pages/index/index'
import PageTransition from '../components/PageTransition.vue'
import Classify from '../pages/classify/classify'
import ItemClassify from '../pages/classify/item_classify'
import Detail from '../pages/goods/detail'
import User from '../pages/user/user'
import Collection from '../pages/collection/collection'
import Login from '../pages/login/login'
import Register from '../pages/login/register'
import Payment from '../pages/payment/payment'
import Forget from '../pages/login/forget.vue'
import ChangePwd from '../pages/login/change_pwd'
import Order from '../pages/order/my_order'
import Shop from '../pages/shop/shop'
import ShopClassify from '../pages/shop/shop_classify'
import ShopInfo from '../pages/shop/shop_info'
import OrderDetail from '../pages/order/order_detail'
import Assement from '../pages/order/assement'
import Aptitude from '../pages/shop/aptitude'
import Confirm from '../pages/goods/confirm'
import UserInfo from '../pages/user/user-info'
import Channel from '../pages/goods/channel'
import SetLocal from '../pages/user/set-local'
import AddLocal from '../pages/user/add-local'
import Logistics from '../pages/order/logistics'
import Agreement from '../pages/login/agreement'
import BackApply from '../pages/order/back_apply'
import MiaoSha from '../pages/miaosha/miaosha'
import TaoTeJia from '../pages/taotejia/taotejia'
import All from '../pages/active/all'
import MeiZhuang from '../pages/active/meizhuang'
import MuYing from '../pages/active/muying'
import JiaDian from '../pages/active/jiadian'
import JiaFang from '../pages/active/jiafang'
Router.prototype.goBack = function () {
    this.isBack = true
    window.history.go(-1)
    router.beforeEach((to, from, next) => {
        let token = localStorage.getItem('token'); 
        let status=to.path=='/login'||to.path=='/register'||to.path=='/assement'||to.path=='/forget'||to.path=='/channel'
        if (token) {
            if(status){
                this.push('/')
            }else{
                next() 
            }
        }else{
            next()
        }
       
      })

}
Vue.use(Router)

const router = new Router({
    routes: [
        {
            path: '/',
            component: PageTransition, // 引入页面切换组件
            children: [
                {
                    path: '/',
                    name: 'index',
                    component: Index
                },
                {
                    path: '/classify',
                    name: 'classify',
                    component: Classify
                },
                {
                    path: '/item_classify',
                    name: 'item_classify',
                    component: ItemClassify
                },
                {
                    path: '/detail',
                    name: 'detail',
                    component: Detail
                },
                {
                    path: '/user',
                    name: 'user',
                    component: User
                },
                {
                    path: '/cart',
                    name: 'cart',
                    component: Collection
                },
                {
                    path: '/login',
                    name: 'login',
                    component: Login
                },
                {
                    path: '/register',
                    name: 'register',
                    component: Register
                },
                {
                    path: '/payment',
                    name: 'payment',
                    component: Payment
                },
                {
                  path: '/forget',
                  name: 'forget',
                  component: Forget
                },
                {
                    path: '/order',
                    name: 'order',
                    component: Order
                },
                {
                    path: '/shop',
                    name: 'shop',
                    component: Shop
                },
                {
                    path: '/shop_classify',
                    name: 'shop_classify',
                    component: ShopClassify
                },
                {
                    path: '/shop_info',
                    name: 'shop_info',
                    component: ShopInfo
                },
                {
                    path: '/change_pwd',
                    name: 'change_pwd',
                    component: ChangePwd
                },
                {
                    path: '/order_detail',
                    name: 'order_detail',
                    component: OrderDetail
                },
                {
                    path: '/assement',
                    name: 'assement',
                    component: Assement
                },
                {
                    path: '/back_apply',
                    name: 'back_apply',
                    component: BackApply
                },
                {
                    path: '/aptitude',
                    name: 'aptitude',
                    component: Aptitude
                },
                {
                    path: '/confirm',
                    name: 'confirm',
                    component: Confirm
                },
                {
                    path: '/user_info',
                    name: 'user_info',
                    component: UserInfo
                },
                {
                    path: '/channel',
                    name: 'channel',
                    component: Channel
                },
                {
                    path: '/set_local',
                    name: 'set_local',
                    component: SetLocal
                },
                {
                    path: '/add_local',
                    name: 'add_local',
                    component: AddLocal
                },
                {
                    path: '/logistics',
                    name: 'logistics',
                    component: Logistics
                },
                {
                    path: '/agreement',
                    name: 'agreement',
                    component: Agreement
                },
                {
                    path: '/miaosha',
                    name: 'miaosha',
                    component: MiaoSha
                },
                {
                	path: '/taotejia',
                    name: 'taotejia',
                    component: TaoTeJia
                },
                {
                	path: '/all',
                    name: 'all',
                    component: All
                },
                {
                	path: '/meizhuang',
                    name: 'meizhuang',
                    component: MeiZhuang
                },
                {
                	path: '/muying',
                    name: 'muying',
                    component: MuYing
                },
                {
                	path: '/jiadian',
                    name: 'jiadian',
                    component: JiaDian
                },
                 {
                	path: '/jiafang',
                    name: 'jiafang',
                    component: JiaFang
                }
            ]
        }
    ]
})
export default router
